package org.example.hadoop;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @Author: Lian Jingwei
 * @Date: 2020/7/11 19:33
 * @Version: 1.0
 */
public class NumReducer extends Reducer<LongWritable, NullWritable, LongWritable, LongWritable> {

    private long sortedNum = 0;

    @Override
    protected void reduce(LongWritable key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        for (NullWritable value : values) {
            sortedNum += 1;
            context.write(new LongWritable(sortedNum), key);
        }
    }
}
